#include "rsp_range.hpp"
#include "../action_constants.hpp"

namespace etcdv3 {
    
void AsyncRangeResponse::ParseResponse(RangeResponse& resp, bool prefix) {
    action = GET_ACTION;
    index = resp.header().revision();
    if (resp.kvs_size() == 0) {
        error_code = 100;
        error_message = "Key not found";
        return;
    } else {
        for (int index = 0; index < resp.kvs_size(); index++) {
            KeyValue kv;
            kv.kvs.CopyFrom(resp.kvs(index));
            values.push_back(kv);
        }

        if (!prefix && values.empty() == false) {
            value = values[0];
            values.clear();
        }
    }
}

}


